/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller.user;

import java.util.List;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.Hashtable;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import queenb.net.entitybean.N100;
import queenb.web.controller.LoginCon;
import queenb.web.controller.QueenbController;
import queenb.web.store.UserStore;
import queenb.web.util.Util;

/**
 *
 * @author thanhct
 */
public class UserController extends QueenbController {

    private Logger logger = Logger.getLogger(UserController.class);
    private List<N100> listUser = new ArrayList<N100>();
    private UserStore store = new UserStore();
    private String txtTest;

    public UserController() {
    }

    public void logOut() {
        try {
            ExternalContext ext = FacesContext.getCurrentInstance().getExternalContext();
            HttpSession session = (HttpSession) ext.getSession(true);
              System.out.println("-------------user login ----------------");
            if (LoginCon.getSessionManager().containsKey(getLoginSession().getLogin().getUserName())) {
                  System.out.println("-------------kiem tra sesision hien tai----------------");
               LoginCon.getSessionManager().remove(getLoginSession().getLogin().getUserName());
                System.out.println("-------------name user ----------------"+getLoginSession().getLogin().getUserName());
            }
            session.invalidate();
            ext.getSessionMap().clear();
            sendRedirect("login.jsp"+Util.convertMD5("/index/login.jsp")+".jsp");
        } catch (Exception ex) {
            System.out.println("Seesion clear error");
            //sendRedirect("index.jsp");
        }
    }

    /**
     * @return the listUser
     */
    public List<N100> getListUser() {
        return listUser;
    }

    /**
     * @param listUser the listUser to set
     */
    public void setListUser(List<N100> listUser) {
        this.listUser = listUser;
    }

    /**
     * @return the txtTest
     */
    public String getTxtTest() {
        if (getLogin() != null
                && getLogin().getUserName() != null) {
            txtTest = getLogin().getUserName();
        }
        return txtTest;
    }

    /**
     * @param txtTest the txtTest to set
     */
    public void setTxtTest(String txtTest) {
        this.txtTest = txtTest;
    }
}
